package com.example.demo.dao.system;

import com.example.demo.model.system.Permission;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PermissionDAO {

    @Select("select * from permission where super_id=#{super_id}")
    public List<Permission> selectBySuperId(Integer super_id);

    @Select("select * from permission")
    public List<Permission> selectAll();

    @Insert("insert into permission(title,url,super_id)values(#{title},#{url},#{super_id})")
    Integer addPermission(Permission permission);

    @Delete("delete from permission where permission_id=#{permission_id}")
    Integer deleteById(Integer permission_id);

    @Update("update permission set title=#{title},url=#{url},super_id=#{super_id} where permission_id=#{permission_id} ")
    Integer updateById(Permission permission);


    //    模糊查询
    @Select("<script>"+
            "select * from permission " +
            "<where>"+
            "<if test=\"title !=null and title != ''\">"+
            "and title like CONCAT('%',#{title},'%')"+
            "</if>"+
            "<if test=\"url !=null and url != ''\">"+
            "and url like CONCAT('%',#{url},'%')"+
            "</if>"+
            "<if test=\"super_id !=null and super_id != ''\">"+
            "and super_id like CONCAT('%',#{super_id},'%')"+
            "</if>"+
            "</where>"+
            "</script>")
    public List<Permission> findPermission(String  title,String url,Integer super_id) ;

}
